﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

using IronOne.SalesOne.BusinessObjects;
using IronOne.SalesOne.DataObjects;
using System.Data;


namespace Facade
{
    public class StructureFacade
    {
        #region User

        LinqUser linqUser = new LinqUser();

        [DataObjectMethod(DataObjectMethodType.Select)]
        public UserInformation GetUserInformation(string userName)
        {
            return linqUser.GetUserInformation(userName);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public User GetUser(Guid userId)
        {
            return linqUser.GetUser(userId);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public User GetUser(string userName)
        {
            return linqUser.GetUser(userName);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<User> GetUsers(string sortExpression)
        {
            return linqUser.GetUsers(sortExpression);
        }

        [DataObjectMethod(DataObjectMethodType.Insert)]
        public void InsertUser(User user)
        {
            linqUser.InsertUser(user);
        }


        [DataObjectMethod(DataObjectMethodType.Insert)]
        public void AddUser(string[] user, User userObj, string[] roles,int userType, int node)
        {
            linqUser.AddUser(user,userObj,roles,userType,node);
        }


        [DataObjectMethod(DataObjectMethodType.Update)]
        public int UpdateUser(User user)
        {
            return linqUser.UpdateUser(user);
        }


        [DataObjectMethod(DataObjectMethodType.Delete)]
        public int DeleteUser(User user)
        {
            return linqUser.DeleteUser(user);
        }

        [DataObjectMethod(DataObjectMethodType.Insert)]
        public void InsertToUserInStructure(Guid userId, short userType, int nodeId)
        {
            linqUser.InsertToUserInStructure(userId, userType, nodeId);
        }

        [DataObjectMethod(DataObjectMethodType.Update)]
        public int UpdateUserInStructure(Guid userId, short userType, int nodeId)
        {
            return linqUser.UpdateUserInStructure(userId, userType, nodeId);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<string> GetSOsInUnit(int unitID)
        {
            return linqUser.GetUsersInUnits(unitID);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<string> GetSOsForUser(string sortExprssion, string userName)
        {
            return linqUser.GetUsersInUnits(sortExprssion, userName);
        }


        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<User> GetUsersInStructure(int userTypeId, int nodeId,int pageNo)
        {
            return linqUser.GetUsersInStructure(userTypeId, nodeId, pageNo);
        }



        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<User> GetUsersInHQ(int userTypeId,int pageNo)
        {
            return linqUser.GetUsersInHQ(userTypeId, pageNo);
        }


        [DataObjectMethod(DataObjectMethodType.Select)]
        public int[] GetStructureForUser(string userName)
        {
            return linqUser.GetStructureForUser(userName);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<User> GetUsersForSOcode(int unitId, int month, int year)
        {
            return linqUser.GetUsersForSOcode(unitId, month, year);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<User> GetUsersForSOcode(int unitId, int month, int year, int pageNo)
        {
            return linqUser.GetUsersForSOcode(unitId, month, year, pageNo);
        }


        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<User> GetSearchUsers(string name, string userId, int pageNo)
        {
            return linqUser.GetSearchUsers(name, userId,pageNo);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<User> GetBlockedUsers(string name, int pageNo)
        {
            return linqUser.GetBlockedUsers(name, pageNo);
        }

        public bool IsPermitted(string userName, string URL)
        {
            return linqUser.IsPermitted(userName, URL);
        }

        public List<TaskCredentials> GetUserCredentials(string userName, string URL)
        {
            return linqUser.GetUserCredentials(userName, URL);
        }
        #endregion

        #region User Type

        LinqUserTypes linqUserTypes = new LinqUserTypes();

        [DataObjectMethod(DataObjectMethodType.Select)]
        public UserType GetUserType(int UserTypeID)
        {
            return linqUserTypes.GetUserType(UserTypeID);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public UserType GetUserTypeForUser(string userName)
        {
            return linqUserTypes.GetUserTypeForUser(userName);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<UserType> GetUserTypeByName(string userTypeName)
        {
            return linqUserTypes.GetUserTypeByName(userTypeName);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<UserType> GetUserTypesForUser(string sortExpression, string userName)
        {
            return linqUserTypes.GetUserTypesForUser(sortExpression, userName);
        }


        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<UserType> GetUserTypes(string sortExpression)
        {
            return linqUserTypes.GetUserTypes(sortExpression);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<UserType> GetUserTypes()
        {
            return linqUserTypes.GetUserTypes();
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<UserType> GetUserTypes(string sortExpression,int pageNo)
        {
            return linqUserTypes.GetUserTypes(sortExpression,pageNo);
        }

        [DataObjectMethod(DataObjectMethodType.Insert)]
        public void InsertUserType(UserType userType)
        {
            linqUserTypes.InsertUserType(userType);
        }

        #endregion

        #region Unit
        LinqUnit linqUnit = new LinqUnit();


        [DataObjectMethod(DataObjectMethodType.Select)]
        public SalesOneUnit GetUnit(int unitId)
        {
            return linqUnit.GetUnit(unitId);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<SalesOneUnit> GetUnits(string sortExpression)
        {
            return linqUnit.GetUnits(sortExpression);
        }

        [DataObjectMethod(DataObjectMethodType.Insert)]
        public void InsertUnit(SalesOneUnit unit)
        {
            linqUnit.InsertUnit(unit);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<SalesOneUnit> GetUnitsInBranch(int branchID)
        {
            return linqUnit.GetUnitsInBranch(branchID);
        }

        public List<SalesOneUnit> GetUnitsInBranch(string sortExpression, string userName)
        {
            return linqUnit.GetUnitsInBranch(sortExpression, userName);
        }

        [DataObjectMethod(DataObjectMethodType.Delete)]
        public int DeleteUnit(SalesOneUnit unit)
        {
            return linqUnit.DeleteUnit(unit);

        }

        [DataObjectMethod(DataObjectMethodType.Update)]
        public int UpdateUnit(SalesOneUnit unit)
        {
            return linqUnit.UpdateUnit(unit);
        }



        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<SalesOneUnit> GetUnitsForBranch(int branchId)
        {
            return linqUnit.GetUnitsForBranch(branchId);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<SalesOneUnit> GetUnitsForBranch(int branchId, int PageNo)
        {
            return linqUnit.GetUnitsForBranch(branchId, PageNo);
        }


        #endregion

        #region UserRole

        LinqUserRole linqUserRole = new LinqUserRole();

        [DataObjectMethod(DataObjectMethodType.Select)]
        public UserRole GetUserRole(Guid roleID)
        {
            return linqUserRole.GetUserRole(roleID);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<UserRole> GetUserRole(string sortExpression)
        {
            return linqUserRole.GetUserRoles(sortExpression);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<UserRole> GetUserRolesForUserType(int userTypeId)
        {
            return linqUserRole.GetUserRolesForUserType(userTypeId);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<UserRole> GetUserRolesForUserType(int userTypeId,int pageNo)
        {
            return linqUserRole.GetUserRolesForUserType(userTypeId,pageNo);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<short> GetUserTypesOfRolesForUser(Guid userId)
        {
            return linqUserRole.GetUserTypesOfRolesForUser(userId);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<UserRole> GetUserRolesForUserType(int userTypeId, int pageNo, string sortExpression)
        {
            return linqUserRole.GetUserRolesForUserType(userTypeId, pageNo, sortExpression);
        }

        [DataObjectMethod(DataObjectMethodType.Insert)]
        public void InsertUserRole(UserRole userRole)
        {
            linqUserRole.InsertUserRole(userRole);
        }

        [DataObjectMethod(DataObjectMethodType.Update)]
        public int UpdateUserRole(UserRole userRole)
        {
            return linqUserRole.UpdateUserRole(userRole);
        }


        [DataObjectMethod(DataObjectMethodType.Delete)]
        public int DeleteUser(UserRole userRole)
        {
            return linqUserRole.DeleteUserRole(userRole);
        }

        #endregion

        #region Asp_net UserRole

        LinqUserRole_aspnet linqUserRole_aspnet = new LinqUserRole_aspnet();

        [DataObjectMethod(DataObjectMethodType.Select)]
        public UserRole_aspnet GetAspnetUserRole(string roleName)
        {
            return linqUserRole_aspnet.GetAsp_netUserRole(roleName);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public UserRole_aspnet GetAspnetUserRole(Guid roleId)
        {
            return linqUserRole_aspnet.GetAsp_netUserRole(roleId);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<UserRole_aspnet> GetAspnetUserRoles(string sortExpression)
        {
            return linqUserRole_aspnet.GetAsp_netUserRoles(sortExpression);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<UserRole_aspnet> GetAspnetUserRoleForUserType(int userTypeId)
        {
            return linqUserRole_aspnet.GetAsp_netUserRolesForUserType(userTypeId);
        }

        //[DataObjectMethod(DataObjectMethodType.Insert)]
        //public void InsertAspnetUserRole(UserRole userRole)
        //{
        //    linqUserRole_aspnet.InsertUserRole(userRole);
        //}

        [DataObjectMethod(DataObjectMethodType.Update)]
        public int UpdateAspnetUserRole(UserRole_aspnet userRole)
        {
            return linqUserRole_aspnet.UpdateAsp_netUserRole(userRole);
        }


        [DataObjectMethod(DataObjectMethodType.Delete)]
        public int DeleteAspnetUser(UserRole_aspnet userRole)
        {
            return linqUserRole_aspnet.DeleteAsp_netUserRole(userRole);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<UserRole_aspnet> GetRolesForUserTypes(int userTypeId)
        {
            return linqUserRole_aspnet.GetAsp_netUserRolesForUserType(userTypeId);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<UserRole_aspnet> GetAllRolesForUserTypes(int[] userTypeId)
        {
            return linqUserRole_aspnet.GetRolesForUserTypes(userTypeId);
        }
        #endregion

        #region Branch
        LinqBranch linqBranch = new LinqBranch();

        [DataObjectMethod(DataObjectMethodType.Select)]
        public DataTable GetDataByCollectionV2(DateTime fromDate, DateTime toDate, int[] brCodes)
        {
            return linqBranch.GetDataByCollectionV2(fromDate, toDate, brCodes);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public Branch GetBranch(int BranchID)
        {
            return linqBranch.GetBranch(BranchID);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public Branch GetBranchByName(string branchName)
        {
            return linqBranch.GetBranchByName(branchName);
        }


        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Branch> GetBranches(string sortExpression)
        {
            return linqBranch.GetBranches(sortExpression);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Branch> GetBranchesV2(string sortExpression, string intranetUsrname)
        {
            return linqBranch.GetBranchesV2(sortExpression, intranetUsrname);
        }

        [DataObjectMethod(DataObjectMethodType.Insert)]
        public void InsertBranch(Branch brch)
        {

            linqBranch.InsertBranch(brch);

        }

        [DataObjectMethod(DataObjectMethodType.Update)]
        public int UpdateBranch(Branch brch)
        {
            return linqBranch.UpdateBranch(brch);
        }


        [DataObjectMethod(DataObjectMethodType.Delete)]
        public int DeleteBranch(Branch brch)
        {
            return linqBranch.DeleteBranch(brch);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Branch> GetBranchesForGroup(int groupId, int page)
        {
            return linqBranch.GetBranchesForGroup(groupId, page);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Branch> GetBranchesForGroup(int groupId)
        {
            return linqBranch.GetBranchesForGroup(groupId);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Branch> GetBranchesForGroupV2(int groupId, string userid)
        {
            return linqBranch.GetBranchesForGroupV2(groupId, userid);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Branch> GetBranchesForGroup(string sortExpression, string userName)
        {
            return linqBranch.GetBranchesForGroup(sortExpression, userName);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public Branch GetBranchForUnit(int unitId)
        {
            return linqBranch.GetBranchForUnit(unitId);
        }

        #endregion

        #region Group
        LinqGroup linqGroup = new LinqGroup();

        [DataObjectMethod(DataObjectMethodType.Select)]
        public SalesOneGroup GetGroup(int GroupId)
        {
            return linqGroup.GetGroup(GroupId);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public SalesOneGroup GetGroup(string userName)
        {
            return linqGroup.GetGroup(userName);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<SalesOneGroup> GetGroups(string sortExpression)
        {
            return linqGroup.GetGroups(sortExpression);
        }

        [DataObjectMethod(DataObjectMethodType.Insert)]
        public void InserGroup(SalesOneGroup broup)
        {

            linqGroup.InsertGroup(broup);

        }

        [DataObjectMethod(DataObjectMethodType.Update)]
        public int UpdateGroup(SalesOneGroup group)
        {
            return linqGroup.UpdateGroup(group);
        }


        [DataObjectMethod(DataObjectMethodType.Delete)]
        public int DeleteGroup(SalesOneGroup group)
        {
            return linqGroup.DeleteGroup(group);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<SalesOneGroup> GetSearchGroups(string name,int page)
        {
            return linqGroup.GetSearchGroups(name, page);
        }
        #endregion

        #region Task
        LinqTask linqTask = new LinqTask();

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Task> GetTasks(string sortExpression)
        {
            return linqTask.GetTasks(sortExpression);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Task> GetTasks(string sortExpression,int pageNo)
        {
            return linqTask.GetTasks(sortExpression,pageNo);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Task> GetTasksForRole(Guid roleId)
        {
            return linqTask.GetTasksForRole(roleId);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Task> GetTasksForModule(Module module)
        {
            return linqTask.GetTasksForModule(module);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Page> GetPagesForTask(Task task)
        {
            return linqTask.GetPagesForTask(task);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public string GetPermissions(Guid roleId, int taskId)
        {
            return linqTask.GetPermissions(roleId, taskId);
        }

        [DataObjectMethod(DataObjectMethodType.Update)]
        public int UpdatePermission(Guid roleId, int taskId, string permissions)
        {
            return linqTask.UpdatePermissions(roleId, taskId, permissions);
        }

        [DataObjectMethod(DataObjectMethodType.Update)]
        public int UpdatePermission(TaskCredentials taskCredentials)
        {
            return linqTask.UpdatePermissions(taskCredentials);
        }


        [DataObjectMethod(DataObjectMethodType.Update)]
        public void InsertPermission(TaskCredentials taskCredentials)
        {
            linqTask.InsertPermission(taskCredentials);
        }


        #endregion

        #region Module
        LinqModule linqModule = new LinqModule();

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Module> GetModules(string sortExpression)
        {
            return linqModule.GetModules(sortExpression);
        }



        #endregion

        #region ActitityPlan
        LinqActivityPlan activityPlan = new LinqActivityPlan();

        [DataObjectMethod(DataObjectMethodType.Select)]
        public DataTable GetActivityPlan(DateTime from, DateTime to, string soCode)
        {
            return activityPlan.GetActivityPlan(from, to, soCode);
        }


        LinqActivityPlan salesActivity = new LinqActivityPlan();
        [DataObjectMethod(DataObjectMethodType.Select)]

        public SalesAppoinments GetActivity(string contractId,string socode, DateTime date)
        {
            return salesActivity.GetActivity(contractId, socode, date);
        }

        public void ClearSupervisorRemark(DateTime date, string soCode)
        {
            salesActivity.ClearSupervisorRemark(date, soCode);
        }

        public ActivityRemark GetRemarkForSO(string soCode, DateTime date)
        {
            return salesActivity.GetRemarkForSO(soCode, date);
        }

        public ActivityRemark GetRemarkForProspect(string soCode, DateTime date)
        {
            return salesActivity.GetRemarkForProspect(soCode, date);
        }

        public void InsertOrUpdateRemark(List<ActivityRemark> updateList, List<ActivityRemark> insertList)
        {
            salesActivity.InsertOrUpdateRemark(updateList, insertList);
        }


        #endregion

        #region Policy


        LinqPolicy policy = new LinqPolicy();
        [DataObjectMethod(DataObjectMethodType.Select)]
        public Policy GetPolicy(string contractId)
        {
            return policy.GetPolicy(contractId);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Policy> GetPoliciesForDate(DateTime fromDate, DateTime toDate, string soCode, int pageNo)
        {
            return policy.GetPoliciesForDate(fromDate, toDate, soCode, pageNo);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Policy> GetPoliciesForDate(DateTime fromDate, DateTime toDate, string soCode)
        {
            return policy.GetPoliciesForDate(fromDate, toDate, soCode);
        }

        #endregion

        #region ProspectQuotations

        LinqProspectQuotations quotations = new LinqProspectQuotations();

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<ProspectQuotations> GetQuotationsBySocode(string socode, DateTime fromDate, DateTime toDate, int pageNo)
        {
            return quotations.GetQuotationsBySocode(socode, fromDate, toDate, pageNo);
        }



        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<ProspectQuotations> GetQuotationsByNo(string socode, string quoNum, DateTime fromDate, DateTime toDate)
        {
            return quotations.GetQuotationsByNo(socode, quoNum, fromDate, toDate);
        }


        [DataObjectMethod(DataObjectMethodType.Select)]
        public ProspectQuotations GetQuotation(string quoNum)
        {
            return quotations.GetQuotation(quoNum);
        }

        

        #endregion

        #region QuoDetails

        LinqQuoDetails quoDetails = new LinqQuoDetails();

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<QuotationDetails> GetQuotationsDetails(string quoNum)
        {
            return quoDetails.GetQuotationsDetails(quoNum);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<String> GetLives(string quoNum)
        {
            return quoDetails.GetLives(quoNum);
        }

        #endregion

        #region Device Mapping

        LingDeviceMapper mapper = new LingDeviceMapper();

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<MappingInfo> GetMappingInfo(int branch, int? unit, string so, int pageNo)
        {
            return mapper.GetMappingInfo(branch, unit, so, pageNo);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public bool UpdateMappingInfo(MappingInfo info)
        {
            return mapper.UpdateMappingInfo(info);
        }

        #endregion


        
    } 
}
